package cn.dyhack.bibiscan.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.dyhack.bibiscan.dao.UserMapper;
import cn.dyhack.bibiscan.dto.UserMap;
import cn.dyhack.bibiscan.po.tables.pojos.User;
import cn.dyhack.bibiscan.service.UserService;
import cn.dyhack.bibiscan.vo.VoUser;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    public boolean addUser(User user) {
        if (userMapper.addUser(user) == null) {
            return false;
        } else {
            return true;
        }
    }

    public VoUser selectUser(String userName) {
        return UserMap.INSTANCE.toVoUser(userMapper.selectUserByName(userName));

    }

    public void delUser(Long id) {

        userMapper.delUser(id);

    }

    public boolean updateUser(User user) {
        if (userMapper.updateUser(user) == null) {
            return false;
        } else {
            return true;
        }
    }

    public VoUser selectUser(Long id) {
        return UserMap.INSTANCE.toVoUser(userMapper.selectUserById(id));
    }

}
